<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('VIEW列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            商户编号：<input type="text" name="shbh"/>
                        </li>

                        <li>
                            统计时间：<input type="text" name="successTime"/>
                        </li>
                        <li>
                            系统收款金额 ：<input type="text" name="payAmount"/>
                        </li>
                        <li>
                            状态：<select name="capitalStatus">
                            <option value="">所有</option>
                            <option value = "未申请">未申请</option>
                            <option value = "申请中">申请中</option>
                            <option value = "驳回">驳回</option>
                            <option value = "已审批">已审批</option>
                        </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="$.table.exportExcel()"
               shiro:hasPermission="channel:vwCapitalInfo:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('channel:vwCapitalInfo:edit')}]];
    var removeFlag = [[${@permission.hasPermi('channel:vwCapitalInfo:remove')}]];
    var prefix = ctx + "channel/vwCapitalInfo";

    $(function () {
        var options = {
            url: prefix + "/list",
            setStatusUrl: ctx+"channel/businessCapital/apply",
            modalName: "资金查询",
            sortName: "successTime",
            sortOrder: "desc",
            showExport: true,
            columns: [{
                checkbox: true
            },
                {
                    field: 'shbh',
                    title: '商户编号',
                    sortable: true
                },
                {
                    field: 'successTime',
                    title: '统计时间',
                    sortable: true
                },
                {
                    field: 'payAmount',
                    title: '系统收款金额',
                    sortable: true
                },
                {
                    field: 'unuseAmount',
                    title: '冻结金额',
                    sortable: true
                },
                {
                    field: 'amount',
                    title: '已提现金额',
                    sortable: true
                },
                {
                    field: 'useAmonut',
                    title: '可提现金额',
                    sortable: true
                },
                {
                    field: 'applyTime',
                    title: '最近申请时间',
                    sortable: true
                },
                {
                    field: 'capitalStatus',
                    title: '状态',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="#" onclick="setStatus(\'' + row.capitalId + '\',\'0\',\'' + row.capitalStatus + '\')"><i class="fa fa-check"></i>撤销申请</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="#" onclick="setApply(\'' + row.shbh + '\',\'1\',\'' + row.capitalStatus + '\',\'' + row.successTime + '\',\'' + row.useAmonut + '\')"><i class="fa fa-check"></i>申请提现</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="#" onclick="setStatus(\'' + row.capitalId + '\',\'2\',\'' + row.capitalStatus + '\')"><i class="fa fa-check"></i>驳回</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="#" onclick="setStatus(\'' + row.capitalId + '\',\'3\',\'' + row.capitalStatus + '\')"><i class="fa fa-check"></i>审批</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /*已支付  状态(0: 未申请 1:申请中 2: 驳回 3. 已审批)*/
    function setApply(id, status, curStatus, successTime, useAmount) {
        if (curStatus === '申请中' && status === '1') {
            $.modal.alertWarning("已经申请了,不需要重新申请！");
            return;
        }
        var url = ctx + 'channel/businessCapital/apply/' + id + '/' + successTime + '/' + useAmount;
        $.modal.open("申请提现", url);
    }

    /*已支付  状态(0: 未申请 1:申请中 2: 驳回 3. 已审批)*/
    function setStatus(capitalId, status, curStatus, successTime, useAmount) {
        if (curStatus !== '申请中' && status === '2') {
            $.modal.alertWarning("只有申请中的才能进行驳回！");
            return;
        } else if (curStatus !== '申请中' && status === '3') {
            $.modal.alertWarning("只有申请中的才能进行审批！");
            return;
        }
        $.modal.confirm("确认要进行此操作吗?", function () {
            var url = $.table._option.setStatusUrl;
            var data = {"capitalId": capitalId, 'status': status};
            $.operate.submit(url, "post", "json", data);
        });
    }

    // window.setInterval(function(){
    //     $.table.refresh();
    // }, 5000)
</script>
</body>
</html>